<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 流年 <liu21st@gmail.com>
// +----------------------------------------------------------------------

// 应用公共文件
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
use think\Db;

//写邮件公共函数
function mailto($to,$title,$content)
{
    $mail = new PHPMailer(true);                              // Passing `true` enables exceptions
    try {
        //Server settings
        $mail->SMTPDebug = 0;                                 // Enable verbose debug output
        $mail->isSMTP();                                      // Set mailer to use SMTP
        $mail->Host = 'smtp.qq.com';  // Specify main and backup SMTP servers
        $mail->SMTPAuth = true;                               // Enable SMTP authentication
        $mail->Username = '634308664@qq.com';                 // SMTP username
        $mail->Password = 'pgqnxlkecezdbcfc';                           // SMTP password
        $mail->SMTPSecure = 'ssl';                            // Enable TLS encryption, `ssl` also accepted
        $mail->Port = 465;                                    // TCP port to connect to

        //Recipients
        $mail->setFrom('634308664@qq.com', '后台管理员');
        $mail->addAddress($to);     // Add a recipient

        //Content
        $mail->isHTML(true);                                  // Set email format to HTML
        $mail->Subject = $title;
        $mail->Body = $content;

        return $mail->send();
    } catch (Exception $e) {
        exception($mail->ErrorInfo);
    }
}
    //写日志公共函数
function writeLog($username,$password,$ip){
     Db::table('tp_log')
         ->insert([
             'username' => $username,
             'password' => $password,
             'time'     => date('Y-m-d  H:i:s',time()),
             'ip'       => $ip
            ]);
     return 1;
    }

    //读取日志公共函数
function readLog($username){
    $list = Db::table('tp_log')
                ->where('username','=',$username)
                ->order('id desc')
                ->select();
    return $list;
}


